﻿@model NationalIT.Trip_Info
@{
    ViewBag.Title = "Trip Info";
    var listCompany = NationalIT.DB.Entities.Company.Where(m=>m.Actived).ToList();
}
<script type="text/javascript">
    $(document).ready(function () {
        var customer_invoiced_date = $("input.date-picker[name=Customer_Invoiced_date]").val();
        if (!$("#Customer_Invoiced").is(":checked")) {
            $("input.date-picker[name=Customer_Invoiced_date]").val('');
        }
        $("#Customer_Invoiced").click(function () {
            if ($(this).is(':checked')) {
                $("input.date-picker[name=Customer_Invoiced_date]").val(customer_invoiced_date);
            } else {
                $("input.date-picker[name=Customer_Invoiced_date]").val('');
            }
        });

        //        autoCompleteByClassName($(":input.Dispatcher"),Html.Raw(ViewBag.dataDispatchers));
        //        autoCompleteByClassName($(":input.Driver"),Html.Raw(ViewBag.dataDriver)); 
        setValueForTotalCharges();
        $("#Detention_pay, #Comfirmed_Rate, #Extra_charges").on("keyup", function () {
            setValueForTotalCharges();
        }).keyup(function (e) {
            if (e.keyCode == 8) {
                setValueForTotalCharges();
            }
        });
        $(".BeforePrintReport").click(function () {
            var printUrl = $(this).attr("href");
            var idlist = $(".chonsen-company").val();
            if (idlist == null || idlist == '' || isNaN(idlist)) {
                alert("Please select company!");
                return false;
            }
            //            $("._CompanyExpenses input:checkbox:checked").each(function () {
            //                idlist += $(this).val() + "-";
            //            });
            $(this).attr("href", addParam(printUrl, "companyID", idlist));
        });
    });
    function setValueForTotalCharges() {
        var value = 0;
        $("#Detention_pay, #Comfirmed_Rate, #Extra_charges").each(function () {
            var addValue = eval($(this).val());
            addValue = isNaN(addValue) ? 0 : addValue;
            value = eval(value + addValue);
        });
        $("#Total_charges").val(value);
    }   
</script>
<div class="row-fluid">
    <div class="span12">
        <h3>
            Trip Info</h3>
        @using (Html.BeginForm(null, null, FormMethod.Post, new { @class = "form-horizontal" }))
        {
            @Html.ValidationSummary(true)                    

            @Html.HiddenFor(model => model.Trip_ID)            
            <div class="row-fluid">
                <div class="span12">
                    <input type="submit" value="Save" class="btn btn-primary" />
                    <a href="/Reports/ShowReport.aspx?ReportName=Invoice&&tripID=@Model.Trip_ID" target="_blank" class="btn btn-primary BeforePrintReport">
                        Print Report</a> 
                    <a href="/TripInfo/InvoicedReport?tripID=@Model.Trip_ID" target="_blank" class="btn btn-primary BeforePrintReport">
                        Pdf Report</a> 
                    @((Model != null && Model.Trip_ID > 0) ? Html.ActionLink("Delete", "Delete", new { arrayID = Model.Trip_ID }, new { @class = "btn btn-danger confirmDelete" }) : new MvcHtmlString(""))
                    @Html.ActionLink("Cancel", "Index", null, new { @class = "btn" })
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">
                    <div class="control-group">
                        <label for="Customer">
                            Customer</label>
                        <select data-placeholder="Select Customer" name="Customer" class=" chosen-with-diselect-customer input-xlarge ">
                            @Html.Raw(ViewBag.dataCustomer)
                        </select>
                        @*<input type="text" name="CustomerDisplay" class = "input-xxlarge CustomerDisplay" value="@(Model!=null && Model.Customer_Info != null ? Model.Customer_Info.Customer_Name : "")" />*@
                        @Html.ValidationMessageFor(model => model.Customer)
                        @*<a href="#AddCustomerInfo" role="button" class="btn btn-primary" data-toggle="modal">                        
                            Customer info</a>*@
                    </div>
                </div>
                <div class="span2">
                    <div class="control-group">
                        <label for="Customer" style="color: #e9f0f9">
                            x
                        </label>
                        <a href="#" class="btn btn-primary">Select By Invoice</a>
                    </div>
                </div>
                @*<div class="span7">
                    <div class="boxScroll _CompanyExpenses"> 
                        <h4 class="text-center">Company</h4>
                        @Html.Partial("_CompanyExpenses", listCompany)
                    </div>
                </div>*@
            </div> 
            <div class="row-fluid">
                <div class="span12">
                    <div class="control-group">
                        <label for="Address">
                            Address</label>
                        @Html.TextBoxFor(model => model.Address, new { @class = "input-xxlarge" })
                        @Html.ValidationMessageFor(model => model.Address)
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span12">
                    <div class="control-group">
                        <label for="Company">
                            Company</label>
                        @*@Html.TextBoxFor(model => model.Company, new { @class = "input-xxlarge" })*@
                        <select data-placeholder="Select Company" name="Company" class="chonsen-company chosen-with-diselect input-xxlarge">
                            @Html.Raw(ViewBag.dataCompany)
                        </select>
                        @Html.ValidationMessageFor(model => model.Company)
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span4">
                    <div class="control-group">
                        <label for="Order_date">
                            Order_date</label>
                        <input type="text" name="Order_date" value="@(Model.Order_date.HasValue ? Model.Order_date.Value.ToString("MM/dd/yyyy") : "")"  class = "input-xlarge date-picker"/>
                        @Html.ValidationMessageFor(model => model.Order_date)
                    </div>
                    <div class="control-group">
                        <label for="PO_">
                            PO#</label>
                        @Html.TextBoxFor(model => model.PO_, new { @class = "input-xlarge" })
                        @Html.ValidationMessageFor(model => model.PO_)
                    </div>
                    <div class="control-group">
                        <label for="Pick_up_location">
                            Pick up location</label>
                        @Html.TextBoxFor(model => model.Pick_up_location, new { @class = "input-xlarge" })
                        @Html.ValidationMessageFor(model => model.Pick_up_location)
                    </div>
                    <div class="control-group">
                        <label for="Delivery_location">
                            Delivery location</label>
                        @Html.TextBoxFor(model => model.Delivery_location, new { @class = "input-xlarge" })
                        @Html.ValidationMessageFor(model => model.Delivery_location)
                    </div>
                    <div class="control-group">
                        <label for="Extra_stops">
                            Extra_stops</label>
                        @Html.TextBoxFor(model => model.Extra_stops, new { @class = "input-xlarge" })
                        @Html.ValidationMessageFor(model => model.Extra_stops)
                    </div>
                    <div class="control-group">
                        <label for="Dispatcher">
                            Dispatcher</label>
                        @*@Html.TextBoxFor(model => model.Dispatcher, new { @class = "input-xlarge" })*@
                        @*<input type="text" class="input-xlarge Dispatcher" name="Dispatcher" value="@Model.Dispatcher" style="margin: 0 auto;" data-provide="typeahead" data-items="4" />*@
                        <select data-placeholder="Select Dispatcher" name="Dispatcher" class="chosen-with-diselect input-xlarge">
                            @Html.Raw(ViewBag.dataDispatchers)
                        </select>
                        @Html.ValidationMessageFor(model => model.Dispatcher)
                    </div>
                    <div class="control-group">
                        <label for="Driver">
                            Driver</label>
                        @*@Html.TextBoxFor(model => model.Driver, new { @class = "input-xlarge" })*@ @*<input type="text" class="input-xlarge Driver" name="Driver" value="@Model.Driver" style="margin: 0 auto;" data-provide="typeahead" data-items="4"/>*@
                        <select data-placeholder="Select Driver" name="Driver" class="chosen-with-diselect input-xlarge">
                            @Html.Raw(ViewBag.dataDriver)
                        </select>
                        @Html.ValidationMessageFor(model => model.Driver)
                    </div>
                </div>
                <div class="span4">
                    <div class="control-group">
                        <label for="Pickup_date">
                            Pickup_date</label>
                        <input type="text" name="Pickup_date" value="@(Model.Pickup_date.HasValue ? Model.Pickup_date.Value.ToString("MM/dd/yyyy") : "")"  class = "input-xlarge date-picker"/>
                        @Html.ValidationMessageFor(model => model.Pickup_date)
                    </div>
                    <div class="control-group">
                        <label for="Loaded_miles">
                            Loaded_miles</label>
                        @Html.TextBoxFor(model => model.Loaded_miles, new { @class = "input-xlarge" })
                        @Html.ValidationMessageFor(model => model.Loaded_miles)
                    </div>
                    <div class="control-group">
                        <label for="Dead_head_miles">
                            Dead_head_miles</label>
                        @Html.TextBoxFor(model => model.Dead_head_miles, new { @class = "input-xlarge" })
                        @Html.ValidationMessageFor(model => model.Dead_head_miles)
                    </div>
                    <div class="control-group">
                        <label for="Comfirmed_Rate">
                            Comfirmed</label>
                        @Html.TextBoxFor(model => model.Comfirmed_Rate, new { @class = "input-xlarge onlyNumber" })
                        @Html.ValidationMessageFor(model => model.Comfirmed_Rate)
                    </div>
                    <div class="control-group">
                        <label for="Extra_charges">
                            Lumber & extra charges</label>
                        @Html.TextBoxFor(model => model.Extra_charges, new { @class = "input-xlarge onlyNumber" })
                        @Html.ValidationMessageFor(model => model.Extra_charges)
                    </div>
                    <div class="control-group">
                        <label for="Detention_pay">
                            Detention pay</label>
                        @Html.TextBoxFor(model => model.Detention_pay, new { @class = "input-xlarge onlyNumber" })
                        @Html.ValidationMessageFor(model => model.Detention_pay)
                    </div>
                    <div class="control-group">
                        <label for="Total_charges">
                            Total_charges</label>
                        @Html.TextBoxFor(model => model.Total_charges, new { @class = "input-xlarge onlyNumber", @readonly = "readonly" })
                        @Html.ValidationMessageFor(model => model.Total_charges)
                    </div>
                </div>
                <div class="span4">
                    <div class="control-group">
                        <label for="Delivery_date">
                            Delivery_date</label>
                        <input type="text" name="Delivery_date" value="@(Model.Delivery_date.HasValue ? Model.Delivery_date.Value.ToString("MM/dd/yyyy") : "")"  class = "input-xlarge date-picker"/>
                        @Html.ValidationMessageFor(model => model.Delivery_date)
                    </div>
                    <div class="control-group">
                        <label for="Equipment_ID">
                            Equipment</label>
                        @*@Html.TextBoxFor(model => model.Equipment_ID, new { @class = "input-xlarge" })*@
                        <select data-placeholder="Select Equipment" name="Equipment_ID" class="chosen-with-diselect input-xlarge">
                            @Html.Raw(ViewBag.dataEquipment)
                        </select>
                        @Html.ValidationMessageFor(model => model.Equipment_ID)
                    </div>
                    <div class="control-group">
                        <label for="Chargebacks">
                            Chargebacks</label>
                        @Html.TextBoxFor(model => model.Chargebacks, new { @class = "input-xlarge onlyNumber" })
                        @Html.ValidationMessageFor(model => model.Chargebacks)
                    </div>
                    <div class="control-group">
                        <label for="Picked" class="checkbox">
                            Picked
                            @Html.CheckBoxFor(model => model.Picked, new { @class = "input-xlarge" })</label>
                        @Html.ValidationMessageFor(model => model.Picked)
                    </div>
                    <div class="control-group">
                        <label for="Deliverd" class="checkbox">
                            Deliverd
                            @Html.CheckBoxFor(model => model.Deliverd, new { @class = "input-xlarge" })</label>
                        @Html.ValidationMessageFor(model => model.Deliverd)
                    </div>
                    @Html.HiddenFor(model => model.Invoice)
                    @if (Model.Invoice != 0)
                    {
                        <div class="control-group">
                            Invoice: <span style="color: Red;">@Model.Invoice</span>
                        </div>
                    }
                    <div class="control-group">
                        <label for="Customer_Invoiced" class="checkbox">
                            Customer_Invoiced
                            @Html.CheckBoxFor(model => model.Customer_Invoiced, new { @class = "input-xlarge" })</label>
                        @Html.ValidationMessageFor(model => model.Customer_Invoiced)
                    </div>
                    <div class="control-group">
                        <label for="Current_Payroll" class="checkbox">
                            Current_Payroll
                            @Html.CheckBoxFor(model => model.Current_Payroll, new { @class = "input-xlarge" })</label>
                        @Html.ValidationMessageFor(model => model.Current_Payroll)
                    </div>
                    <div class="control-group">
                        <label for="Driver_paid" class="checkbox">
                            Driver_paid
                            @Html.CheckBoxFor(model => model.Driver_paid, new { @class = "input-xlarge" })
                        </label>
                        @Html.ValidationMessageFor(model => model.Driver_paid)
                    </div>
                    <div class="control-group">
                        <label for="Customer_Invoiced_date">
                            Customer_Invoiced_date</label>
                        <input type="text" name="Customer_Invoiced_date" value="@(Model.Customer_Invoiced_date.ToString("MM/dd/yyyy"))"  class = "input-xlarge date-picker"/>
                        @Html.ValidationMessageFor(model => model.Customer_Invoiced_date)
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span12">
                    <div class="control-group">
                        <label for="Comment">
                            Comment</label>
                        @Html.TextAreaFor(model => model.Comment, new { @class = "input-xxlarge", rows = "5" })
                        @Html.ValidationMessageFor(model => model.Comment)
                    </div>
                </div>
            </div>                       
        }
    </div>
</div>
<div id="AddCustomerInfo" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1"
    aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3 id="myModalLabel1">
            Customer Info</h3>
    </div>
    <div class="modal-body" id="Ajax">
        <label for="Customer">
            Customer</label>
        <input type="text" class="span5 Customer" name="Customer" value="@(Model != null && Model.Customer_Info != null ? Model.Customer_Info.Customer_Name : "")"/>
        <div id="resultCustomerInfo" class="resultCustomer">
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">
            Close</button>
    </div>
</div>
